<%@include file="/include/header.jsp" %>
<%@include file="/include/headerBec.jsp" %>
<script>
    function agregarLibro(){
        var form = document.getElementById("prestamoLibroForm");
        if(form.isbnLibro.value.trim() == "" || form.fecDevolucion.value.trim() == "" || form.libro.value.trim() == "") {
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#dialog-message" ).dialog({minHeight: 70, height: 180, modal: true, buttons: {Ok: function() {$( this ).dialog( "close" );}}});
        } else {
            form.cmd.value = "agregarLibro";
            form.submit();
        }
    }
    
    function descartarLibro(codigo){
        location.href = "./PrestamoLibro.jsa?cmd=descartarLibro&index=" + codigo;
        /*var form = document.getElementById("prestamoLibroForm");
        form.cmd.value = "descartarLibro";
        form.submit();*/
    }
    
    function prestarLibros(){
        var form = document.getElementById("prestamoLibroForm");
        form.cmd.value = "realizarPrestamo";
        form.submit();       
    }
    
    
    
    function buscarLibro(){
        var form = document.getElementById("prestamoLibroForm");
        var url = "";
        if (form.isbnLibro.value == ""){
            url = "./Libro.jsa?cmd=buscarLibro";
            window.open(url,"recWin", "HEIGHT=700, WIDTH=575, MODAL=YES, scrollBars=YES");
        }else{
            form.cmd.value = "cargarLibro";
            form.isbn.value = "";
            form.fecDevolucion.value = "";
            form.libro.value = "";
            form.submit();
        }
    }
    
    function clean(){
        var form = document.getElementById("prestamoLibroForm");
        form.isbn.value = "";
        form.isbnLibro.value = "";
        form.fecDevolucion.value = "";
        form.libro.value = "";
        form.cmd.value = "init";
        form.submit();
    }
    
    $(document).ready(function(){
        $("#fechaDev").datepicker({dateFormat:'dd-M-yy', minDate: new Date()});
        $('#fechaDev').datepicker('setDate', '+0');
        var divBg2 = document.getElementById("background2");
        divBg2.style.height = "901px";
    });
</script>
<div class="content">
    <html:form action="/PrestamoLibro" styleId="prestamoLibroForm" onsubmit="return validarForm()">
        <html:hidden property="cmd" value="" />
        <html:hidden property="isbn" />
        <table border="0" class="form">
            <caption class="titleSeg">Prestamo de Libros</caption>
            <tr class="campos">
                <td class="label">ISBN:&nbsp;&nbsp;</td>
                <td class="control">
                    <html:text property="isbnLibro" styleClass="tinput150" />
                    <a href="javascript:buscarLibro();"><html:img src="./images/search.png" /></a>
                </td>
                <td width="50px"></td>
                <td class="label">Fecha de entrega:&nbsp;&nbsp;</td>
                <td class="control">
                    <html:text property="fecDevolucion" styleId="fechaDev" styleClass="tinput150" readonly="true" />
                </td>
            </tr>
            <tr class="campos">
                <td class="label">Nombre Libro:&nbsp;&nbsp;</td>
                <td class="control" colspan="4"><html:text property="libro" styleClass="tinput400" readonly="true" /></td>
            </tr>
            <logic:present name="msg">
            <tr>
                <td colspan="5">
                    <html:img src="./images/ok.png"/>&nbsp;
                    <html:messages id="mensaje" name="msg">
                        <bean:write name="mensaje"/>
                    </html:messages>
                </td>
            </tr>
            </logic:present>
            <logic:present name="errors">
            <tr>      
                <td colspan="5" class="errors">
                    <html:img src="./images/error.png"/>&nbsp;
                    <html:messages id="mensaje" name="errors">
                        <bean:write name="mensaje"/>
                    </html:messages>
                </td>
            </tr>
            </logic:present>
            <tr class="botones">
                <td colspan="5">
                    <div style="float: left">
                        <logic:equal name="agregar" value="Y">
                            <html:button property="agregar" value="Agregar" styleClass="button" onclick="agregarLibro();" />
                        </logic:equal>
                        <logic:equal name="agregar" value="N">
                            <html:button property="agregar" value="Agregar" styleClass="button" disabled="true" />
                        </logic:equal>
                        <html:button property="limpiar" value="Limpiar" styleClass="button" onclick="clean();" />
                    </div>
                </td>
            </tr>
        </table>
        <logic:notEmpty name="librosListReq">
            <center>
                <div style="width:60%; text-align: left">
                    <display:table pagesize="10" name="librosListReq" class="results" id="results" style="width:100%;">
                        <display:column property="index" title="Descartar?" decorator="com.uca.sisbec.decorators.PrestamoLibroDecorator" />
                        <display:column property="isbn" title="ISBN" />
                        <display:column property="libro" title="Libro" />
                        <display:column property="fecDevolucion" title="Fecha Devolucion" />
                    </display:table>
                    <br />
                    <html:button property="prestar" value="Realizar Prestamo" styleClass="button" onclick="prestarLibros();" style="text-align: center;" />
                </div>
            </center>
        </logic:notEmpty>
    </html:form>
</div>
<logic:present name="abrirBusqueda">
<script>
    url = "./Libro.jsa?cmd=buscarLibro";
    window.open(url,"recWin", "HEIGHT=700, WIDTH=575, MODAL=YES, scrollBars=YES");
</script>
</logic:present>

    <!-- DIVS DE MENSAJES DE VALIDACIONES -->
    <div id="dialog-message" style="display: none" title="Advertencia">
	<p>
            <span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
            Todos los datos del pr&eacute;stamo son obligatorios
	</p>
    </div>
    <!-- ******************************* -->
<%@include file="/include/footerBec.jsp" %>
<%@include file="/include/footer.jsp" %>
